<template>
  <div class="app-container">
    <div class="block">
      <el-row>
        <el-col :span="24">
          <el-button
            type="success"
            size="mini"
            icon="el-icon-plus"
            @click.native="add"
          >{{ $t('button.add') }}</el-button>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-edit"
            @click.native="update"
          >{{ $t('button.edit') }}</el-button>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click.native="remove"
          >{{ $t('button.delete') }}</el-button>
        </el-col>
      </el-row>
    </div>

    <el-table
      :data="list"
      v-loading="listLoading"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      @current-change="handleCurrentChange"
      @row-click="clickRow"
    >
      <el-table-column label="ID">
        <template slot-scope="scope">{{scope.row.id}}</template>
      </el-table-column>
      <el-table-column label="标签名称">
        <template slot-scope="scope">{{scope.row.name}}</template>
      </el-table-column>
      <el-table-column label="关联商品数量">
        <template slot-scope="scope">{{scope.row.labelGoodsList.length}}</template>
      </el-table-column>
      <el-table-column label="商品管理">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-s-operation"
            @click.native="goodsManagementButton(scope.row.labelGoodsList)"
          >管理</el-button>
        </template>
      </el-table-column>
      <el-table-column label="是否首页推荐">
        <template slot-scope="scope">{{ scope.row.recommend=='1' ? "是" :"否" }}</template>
      </el-table-column>
    </el-table>

    <el-dialog :title="formTitle" :visible.sync="formVisible" width="70%">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-row>
              <el-col :span="24">
                <el-form-item label="标签名称" prop=" name">
                  <el-input v-model="form.name" minlength="1"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="是否首页推荐">
                  <el-radio-group v-model="form.recommend">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>

        <el-form-item>
          <el-button type="primary" @click="save">{{ $t('button.submit') }}</el-button>
          <el-button @click.native="formVisible = false">{{ $t('button.cancel') }}</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="商品管理" :visible.sync="attrKey.visible" width="70%">
      <el-table
        :data="attrKey.goodsList"
        v-loading="listLoading"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column label="商品名称">
          <template slot-scope="scope">{{scope.row.goods.name}}</template>
        </el-table-column>
        <el-table-column label="图片">
          <template slot-scope="scope">
            <img
              :src="apiUrl+ '/file/getImgStream?idFile=' +scope.row.goods.pic"
              style="width:50px;"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click.native="goodsManagementDeleteGood(scope.row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script src="./tags.js"></script>


<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>
